package com.example.myblog.utils;

import com.example.myblog.dto.UserDTO;

/**
 * @author 叶兴
 */
public class UserThreadLocal {
    private static final ThreadLocal<UserDTO> USER_DTO_THREAD_LOCAL = new ThreadLocal<>();

    public static void setUserDto(UserDTO userDTO) {
        USER_DTO_THREAD_LOCAL.set(userDTO);
    }

    public static void clearUserDto() {
        USER_DTO_THREAD_LOCAL.remove();
    }

    public static UserDTO getUserDto() {
        return USER_DTO_THREAD_LOCAL.get();
    }

    public static String getUserDtoName() {
        UserDTO userDto = getUserDto();
        return userDto == null ? null : userDto.getUserName();
    }



}
